package com.example.wc.logindemolistview;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by hui on 2017/2/17.
 */

//public abstract class SingleFragmentActivity extends FragmentActivity {
public abstract class SingleFragmentActivity extends AppCompatActivity {

    protected abstract Fragment createFragment();

    @Override
    public void onCreate(Bundle savedInstanceState) {

        //请注意注释的3句bug:一旦设置自定义标题栏，本抽象类SingleFragmentActivity将变得不通用；
        // 解决办法，定义同样的抽象类自定义标题（不推荐）或者在fragment中自定义布局组件和主题栏一样
//        setTheme(R.style.CustomTitleBarTheme);
        super.onCreate(savedInstanceState);
//        this.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
        setContentView(R.layout.activity_fragment);
//        getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE,R.layout.login_title_bar);


        FragmentManager fm = getSupportFragmentManager();
        Fragment fragment = fm.findFragmentById(R.id.fragment_container);

        if(fragment == null){
            fragment = createFragment();
            fm.beginTransaction()
                    .add(R.id.fragment_container, fragment)
                    .commit();
        }
    }
}
